#include <bits/stdc++.h>
using namespace std;
int t,n,m,l,u,ans1,ans2,d[100003],v[100003],a[100003],p[100003];

int main()
{
	freopen("detect4.in","r",stdin);
	freopen("detect.out","w",stdout);
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d%d%d",&n,&m,&l,&u);
		ans1=ans2=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d%d%d",d+i,v+i,a+i);
		}
		for(int i=0;i<m;i++)
		{
			scanf("%d",&p[i]);
		}
		for(int i=0;i<n;i++)
		{
			if(v[i]<=u && a[i]<=0)
			{
				continue;
			}
			if(v[i]<=u && a[i]>0)
			{
				int d1=(u*u-v[i]*v[i])/(a[i]<<1);
				if(d[i]+d1<p[m-1])ans1++;
			}
			if(v[i]>u && a[i]>=0)
			{
				if(d[i]<p[m-1])
					ans1++;
			}
			if(v[i]>u && a[i]<0)
			{
				int d1=(v[i]*v[i]-u*u+((-a[i])<<1)-1)/((-a[i])<<1);
				if(*lower_bound(p,p+m,d[i])<=d[i]+d1)ans1++;
			}
			
		}
		printf("%d %d\n",ans1,(ans1?m-1:m));
	}
	
	return 0;
}
